/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import TableView.DepartmentTable;
import TableView.DeptinterdependencyTable;
import data.Departments;
import data.Deptinterdependency;
import data.Sections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.TableModel;
import util.BaseDAO;

/**
 *
 * @author Hùng
 */
public class DepartmentDAO extends BaseDAO {

    public List<Departments> getAlldepartment() {
        String hql = "from Departments";
        List<Departments> ldept = executeHQLQuery(hql);
        return ldept;
    }
      public Departments getDepartmentById(int deptNo) {
        String hql = "from Departments s where s.deptno ="+ deptNo;
        List<Departments> ldept = executeHQLQuery(hql);
        if(ldept.size() == 0 )
        {
            return null;
        }
        return ldept.get(0);
    }
      public Departments getDepartmentByName(String deptName) {
        String hql = "from Departments s where s.deptname = '"+ deptName+"'";
        List<Departments> ldept = executeHQLQuery(hql);
        if(ldept.size() == 0 )
        {
            return null;
        }
        return ldept.get(0);
    }
      public DepartmentTable ShowTableDepartment() {
		DepartmentTable model = new DepartmentTable(getAll());
		return model;
	}

	public void actionEdit(Departments dm) {
		executeUpdateHQLQuery(dm);
	}

	public List<Departments> getAll() {
		String sql = " from Departments";
		return executeHQLQuery(sql);
	}

	public ComboBoxModel getComboBoxModel() {
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		model.addElement("-----None-----");
		for (Departments dm : getAll()) {
			model.addElement(dm.getDeptname());
		}
		return model;
	}

	public List<Deptinterdependency> getALLDepinterdependency() {
		String sql = "from Deptinterdependency";
		return executeHQLQuery(sql);
	}

	public Departments getDepartmentByTagName(String department) {
		String hql = "from Departments a where a.deptname = '" + department + "'";
		List<Departments> ldep = executeHQLQuery(hql);
		if (ldep.size() == 0) {
			return null;
		}
		return ldep.get(0);
	}

	

	public TableModel ShowTableTableDepinterDependency() {
            List<Deptinterdependency> ldep = getALLDepinterdependency();
		DeptinterdependencyTable model = new DeptinterdependencyTable(ldep);
		return model;
	}
   
}
